1697A - Parkway Walk - CodeForces Solution


greedy implementation *800

Please click on ads to support us..

Python Code:

t=int(input())
for i in range(t):
    x=input()
    n=int(x.split()[0])
    m=int(x.split()[1])
    a=input()
    a1=a.split()
    for i in range(n):
        a1[i]=int(a1[i])
    if m>sum(a1): print(0)
    else: print(sum(a1)-m)

C++ Code:

#include <bits/stdc++.h>
using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int l;
  cin>>l;
  while(l--){
    int a, k;
    cin>>a>>k;
    int x, add = 0;
    for(int i = 0; i < a; i++){
      cin>>x;
      add += x;
    }
    if(add - k <= 0){
      cout<<0<<"\n";
    }
    else{
      cout<<(add-k)<<"\n";
    }
  }
}


Comments

Submit
0 Comments
More Questions

931A - Friends Meeting
1594A - Consecutive Sum Riddle
1466A - Bovine Dilemma
454A - Little Pony and Crystal Mine
2A - Winner
1622B - Berland Music
1139B - Chocolates
1371A - Magical Sticks
1253A - Single Push
706B - Interesting drink
1265A - Beautiful String
214A - System of Equations
287A - IQ Test
1108A - Two distinct points
1064A - Make a triangle
1245C - Constanze's Machine
1005A - Tanya and Stairways
1663F - In Every Generation
1108B - Divisors of Two Integers
1175A - From Hero to Zero
1141A - Game 23
1401B - Ternary Sequence
598A - Tricky Sum
519A - A and B and Chess
725B - Food on the Plane
154B - Colliders
127B - Canvas Frames
107B - Basketball Team
245A - System Administrator
698A - Vacations